﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Event Bus</title>
<link type="text/css" rel="stylesheet" href="../bootstrap.min.css" />
</head>

<body>

<div class="document-contents">

<h3>Introduction</h3>
<p style="height: 20px"><strong>Pub/sub</strong> event model is widely used in the client side. ASP.NET Boilerplate 
includes a <strong>simple global event bus</strong> to <strong>register</strong> to and 
<strong>trigger</strong> <strong>events</strong>.</p>
<h3>Register To Events</h3>
	<p>You can use <strong>abp.event.on</strong> to <strong>register</strong> to 
	a <strong>global event</strong>. An example registration:</p>
	<pre lang="cs">abp.event.on(&#39;itemAddedToBasket&#39;, function (item) {
    console.log(item.name + &#39; is added to basket!&#39;);
});</pre>

<p>Firt argument is <strong>unique name of the event</strong>. Second one is a
<strong>callback function</strong> that is called when the specified event is 
triggered.</p>
	<p>You can use <strong>abp.event.off</strong> method to <strong>unregister</strong> 
	from an event. Notice that; same function should be provided in order to 
	unregister. So, for the example above, you should set the callback function 
	to a variable, then use both in <strong>on</strong> and <strong>off</strong> 
	methods.</p>
	<h3>Trigger Events</h3>
	<p><strong>abp.event.trigger</strong> is used to <strong>trigger</strong> a
	<strong>global event</strong>. Example trigger code for the event registered 
	above:</p>
	<pre lang="js">abp.event.trigger(&#39;itemAddedToBasket&#39;, {
    id: 42,
    name: &#39;Acme Light MousePad&#39;
});</pre>
	<p>Firt argument is <strong>unique name of the event</strong>. Second one is 
	the (optional) <strong>event argument</strong>. You can add any number of 
	arguments and get them in the callback method.</p>

</div>

</body>

</html>
